import 'package:flutter/material.dart';

class WidgetProgressBar extends StatefulWidget {
  final int maxLenth; //最大星级
  final int indexBar; //当前的星级
  final double width;
  final double height;
  final Color colorsType;

  const WidgetProgressBar(
      {Key key, this.maxLenth, this.indexBar, this.width, this.height, this.colorsType})
      : super(key: key);

  @override
  _widgetProgressState createState() => _widgetProgressState();
}

class _widgetProgressState extends State<WidgetProgressBar> {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Container(
      width: widget.width,
      height: widget.height,
      child: ListView.builder(
        itemBuilder: (context, index) {
          return progressItem(index);
        },
        itemCount: widget.maxLenth,
        physics: new NeverScrollableScrollPhysics(),
        scrollDirection: Axis.horizontal,
      ),
    );
  }

  Widget progressItem(int index) {
    bool isStar = false;
    if (index <= widget.indexBar) {
      isStar = true;
    }
    return Container(
      child: Icon(
        isStar ? Icons.star : Icons.star_border,
        color: widget.colorsType,
      ),
    );
  }
}
